﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using IterationLife.ContentResources.Models;
using Util;
using Util.Domains;
using Util.Domains.Auditing;
using Util.Domains.Trees;

namespace IterationLife.Educations.Models {
    /// <summary>
    /// 课程大纲
    /// </summary>
    [Description( "课程大纲" )]
    public partial class Syllabus : TreeEntityBase<Syllabus>,IDelete,IAudited {
        /// <summary>
        /// 初始化课程大纲
        /// </summary>
        public Syllabus()
            : this( Guid.Empty, "", 0 ) {
        }

        /// <summary>
        /// 初始化课程大纲
        /// </summary>
        /// <param name="id">课程大纲标识</param>
        /// <param name="path">路径</param>
        /// <param name="level">级数</param>
        public Syllabus( Guid id, string path, int level )
            : base( id, path, level ) {
        }

        /// <summary>
        /// 名称
        /// </summary>
        [Required(ErrorMessage = "名称不能为空")]
        [StringLength( 200, ErrorMessage = "名称输入过长，不能超过200位" )]
        public string Name { get; set; }
        /// <summary>
        /// 教材编号
        /// </summary>
        public Guid? TextBookId { get; set; }
        /// <summary>
        /// 内容资源编号
        /// </summary>
        public Guid? ContentResourceId { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public Guid? CreatorId { get; set; }
        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? LastModificationTime { get; set; }
        /// <summary>
        /// 最后修改人
        /// </summary>
        public Guid? LastModifierId { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        [Required(ErrorMessage = "是否删除不能为空")]
        public bool IsDeleted { get; set; }
        
        /// <summary>
        /// 内容资源
        /// </summary>
        public virtual ContentResource ContentResource { get; set; }
        
        /// <summary>
        /// 教材
        /// </summary>
        public virtual TextBook TextBook { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "课程大纲编号", Id );
            AddDescription( "父编号", ParentId );
            AddDescription( "名称", Name );
            AddDescription( "教材编号", TextBookId );
            AddDescription( "内容资源编号", ContentResourceId );
            AddDescription( "级数", Level );
            AddDescription( "启用", Enabled.Description() );
            AddDescription( "排序号", SortId );
            AddDescription( "路径", Path );
            AddDescription( "创建时间", CreationTime );
            AddDescription( "创建人", CreatorId );
            AddDescription( "最后修改时间", LastModificationTime );
            AddDescription( "最后修改人", LastModifierId );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( Syllabus newEntity ) {
            AddChange( "Id", "课程大纲编号", Id, newEntity.Id );            
            AddChange( "ParentId", "父编号", ParentId, newEntity.ParentId );
            AddChange( "Name", "名称", Name, newEntity.Name );
            AddChange( "TextBookId", "教材编号", TextBookId, newEntity.TextBookId );
            AddChange( "ContentResourceId", "内容资源编号", ContentResourceId, newEntity.ContentResourceId );
            AddChange( "Level", "级数", Level, newEntity.Level );
            AddChange( "Enabled", "启用", Enabled, newEntity.Enabled );
            AddChange( "SortId", "排序号", SortId, newEntity.SortId );
            AddChange( "Path", "路径", Path, newEntity.Path );
            AddChange( "CreationTime", "创建时间", CreationTime, newEntity.CreationTime );
            AddChange( "CreatorId", "创建人", CreatorId, newEntity.CreatorId );
            AddChange( "LastModificationTime", "最后修改时间", LastModificationTime, newEntity.LastModificationTime );
            AddChange( "LastModifierId", "最后修改人", LastModifierId, newEntity.LastModifierId );
        }
    }
}